package tw.miku.model.game.card;

import java.nio.charset.CharacterCodingException;
import java.util.ArrayList;

import org.apache.mina.core.buffer.IoBuffer;
import org.dom4j.Element;

import tw.miku.model.ICard;
import tw.miku.model.ISendable;
import tw.miku.model.game.skill.Skill;
import tw.miku.util.BufferUtility;

public class Hero implements ICard, ISendable
{

	public int id;
	public int life = 4;
	public String name;
	public String pic;

	public ArrayList<Skill> skills;

	public Hero()
	{
		skills = new ArrayList<>();
	}

	@Override
	public String getName()
	{
		return name;

	}

	@Override
	public Element getXmlInfo()
	{
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public IoBuffer getInfo() throws CharacterCodingException
	{
		IoBuffer buff = BufferUtility.newInstance();
		buff.putUnsignedInt(id);
		buff.putUnsignedInt(life);
		BufferUtility.writeString(buff, name);
		BufferUtility.writeString(buff, pic);
		BufferUtility.writeArray(buff, skills);
		buff.flip();
		// buff.putUnsignedInt(buff.limit() - 4);
		// buff.free();
		return buff;
	}

	@Override
	public int getId()
	{
		return id;
	}

}
